In [ ]:
%matplotlib nbagg
import matplotlib.pyplot as plt
import numpy as np
Get some data to play with
In [ ]:
from sklearn.datasets import load_digits
digits = load_digits()
In [ ]:
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(digits.data,
digits.target)
In [ ]:
from sklearn.svm import LinearSVC
1) Instantiate an object and set the parameters
In [ ]:
svm = LinearSVC(C=0.1)
2) Fit the model
In [ ]:
svm.fit(X_train, y_train)
3) Apply / evaluate
In [ ]:
print(svm.predict(X_train))
print(y_train)
In [ ]:
svm.score(X_train, y_train)
In [ ]:
svm.score(X_test, y_test)
In [ ]:
from sklearn.ensemble import RandomForestClassifier
In [ ]:
rf = RandomForestClassifier(n_estimators=50)
In [ ]:
rf.fit(X_train, y_train)
In [ ]:
rf.score(X_test, y_test)
In [ ]:
%load https://raw.githubusercontent.com/scikit-learn/scikit-learn/master/examples/classification/plot_classifier_comparison.py
In [ ]:
# %load solutions/train_iris.py